<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/cart.css" rel="stylesheet" type="text/css">
<script language="javascript">
function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>

<?php
$path = '../Mkart/';
include($path."common.php");

$oid = $_GET['oid'] ;

$sql_edit = "select * from  kart_order where order_id = '$oid' " ;
$result_edit = mysql_query($sql_edit);
$row_edit=mysql_fetch_object($result_edit);
$type = $row_edit->order_type;						//
$process_date = $row_edit->order_date;						//分期日期
$process_time = $row_edit->order_time;						//分期時間
$ord_invoice = $row_edit->order_invoice;						//訂單發票抬頭
$ord_invoiceno = $row_edit->order_invoiceno;						//訂單統一編號
$ord_stage = $row_edit->order_stage;						//分期期數
$amount = $row_edit->order_price ;								//金額

//============================================
include($path."order_mail.php");
include($path."mailsend.php");
//============================================

$ord_dt = substr($process_date,0,4) . "年" .  substr($process_date,4,2) . "月"  . substr($process_date,6,2) . "日&nbsp;&nbsp;" .  substr($process_time,0,2) . ":" .  substr($process_time,2,2) . ":"  . substr($process_time,4,2)  ;

switch($type){
	////ATM轉帳。
	case "1_1" :
	$type_table .= "<table width=100% border=1 align=center>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center class=Sky>付款方式</td>" ;
	$type_table .= "<td align=center class=Sky>銀行代號</td>" ;
	$type_table .= "<td align=center class=Sky>帳號</td>" ;
	$type_table .= "<td align=center class=Sky>戶名</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center>ATM轉帳</td>" ;
	$type_table .= "<td align=center>土地銀行(代號005)青年分行</td>" ;
	$type_table .= "<td align=center>０３８－００５－２２４９１５</td>" ;
	$type_table .= "<td align=center>吳瑞美</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "</table>" ;
	break;
	////銀行匯款。
	case "1_2" :
	$type_table .= "<table width=100% border=1 align=center>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center class=Sky>付款方式</td>" ;
	$type_table .= "<td align=center class=Sky >銀行代號</td>" ;
	$type_table .= "<td align=center class=Sky>帳號</td>" ;
	$type_table .= "<td align=center class=Sky>戶名</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center></td>" ;
	$type_table .= "<td align=center></td>" ;
	$type_table .= "<td align=center></td>" ;
	$type_table .= "<td align=center></td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "</table>" ;
	break;
	////WebAtm。
	case "1_3" :
	$type_table .= "<table width=100% border=1 align=center>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center class=Sky>付款方式</td>" ;
	$type_table .= "<td align=center class=Sky>付款說明</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center>WebAtm</td>" ;
	$type_table .= "<td align=left>結帳後點選進入WebATM線上轉帳。使用本付款方式，您需要持有晶片卡讀卡機，任何銀行之晶片金融卡皆可使用。線上轉帳時請您將您的IC晶片金融卡插入讀卡機後，輸入晶片卡密碼，您即可利用金融卡進行線上轉帳交易。(※請先確認讀卡機與電腦連線完成)。本交易由金融卡晶片本身產製驗證碼，傳輸過程均經押碼加密，僅有您的發卡行可解開驗證碼，請安心使用。交易金額與匯款帳號由電腦自動產生。
</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "</table>" ;
	break;
	////貨到付款。
	case "1_4" :
	$type_table .= "<table width=100% border=1 align=center>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center class=Sky>付款方式</td>" ;
	$type_table .= "<td align=center class=Sky>付款說明</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "<tr>" ;
	$type_table .= "<td align=center>貨到付款</td>" ;
	$type_table .= "<td align=center>收貨的同時把款項交給宅配人員。</td>" ;
	$type_table .= "</tr>" ;
	$type_table .= "</table>" ;
	break;
}
?>

<table width="594" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td id="order_process"></td>
  </tr>
</table>



<div id=div_print>
<table width=750 border=1 align=center>
<tr>
<td colspan="2" align=center valign="middle" class="title"><h3>訂購確認單</h3></td>

</tr>
<tr>
<td align=right width=20% class="blue">交易單號：</td>
<td align=left><?php echo $oid?></td>
</tr>
<tr>
<td align=right class="blue">交易金額：</td>
<td align=left class="Sky"><?php echo $amount?></td>
</tr>

<tr>
<td align=right class="blue">處理時間：</td>
<td align=left><?php echo $ord_dt?></td>
</tr>
<?php
if($ord_invoice){ 
?>

<tr>
<td align=right class="blue">發票抬頭：</td>
<td align=left class="Sky"><?php echo $ord_invoice?></td>
</tr>
<?php
}
if($ord_invoiceno){ 
?>

<tr>
<td align=right class="blue">統一編號：</td>
<td align=left><?php echo $ord_invoiceno?></td>
</tr>
<?php
} 
?>

<tr>
<td align=right class="blue">商品明細：</td>
<td align=left>
<table width=100% border=1 align=center cellpadding="6" cellspacing="0">
<td align=left class="Sky" >商品名稱</td>
<td align=center width=20% class="Sky">單價</td>
<td align=center width=20% class="Sky">數量</td>
<td align=center width=20% class="Sky">小計</td>
<?php

$item_totalprice = 0;

$sql_item = "select * from  order_item where order_id = '$oid' order by order_id" ;
$result_item = mysql_query($sql_item);
while($row_item=mysql_fetch_object($result_item)){
$item_no = $row_item->item_id;											//商品編號
$item_amount = $row_item->item_amount;						//商品購買數量



$sql_pd = "select * from  product where id = '$item_no' " ;
$result_pd = mysql_query($sql_pd);
$row_pd = mysql_fetch_object($result_pd);
$pd_name = $row_pd->name;												//商品名稱 

$item_price = $row_pd->price_2 ;
$item_total = $item_price * $item_amount;

$item_totalprice += $item_total;
?>

<tr>
<td align=left><?php echo $pd_name?></td>
<td align=center><?php echo $item_price?></td>
<td align=center><?php echo $item_amount?></td>
<td align=center><?php echo $item_total?></td>
</tr>
<?php
} 
?>

</table>
</td>
</tr>

<tr>
<td align=right class="blue">交易狀態：</td>
<td align=left class="Sky"><span class="red">交易完成</span></td>
</tr>

<tr>
<td align=right class="blue">付款方式：</td>
<td align=left><?php echo $type_table?></td>
</tr>

<tr>
<td align=right class="blue">合計：</td>
<td align=left>小計總合:<? echo $item_totalprice ?> + 運費:<? echo $amount - $item_totalprice ?> = 交易金額:<span ><?php echo $amount?></span></td>
</tr>

</table>
<hr />
</div>
<div id="sumbit_print"><table width="750px" border="0" align="center">
  <tr>
    <td width="50%" height="33" align="right"><input name="b_print" type="button" onclick="printdiv('div_print');" value=" 列印" /></td>
    <td align="left" width="50%"><input name="div_colse" type="button" value="關閉" onclick="window.opener=null;window.close();" /></td>
  </tr>
</table>
</div>
